package com.geotmt.billingcenter.config.hadoop;


import org.apache.tomcat.jdbc.pool.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.annotation.Resource;


/**
 * @Description hadoop JDBC 类（暂时无用）
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/3/19 14:15
 * @Version     v1
 **/
//@Configuration
public class HiveJdbcConfig {
    private static final Logger logger = LoggerFactory.getLogger(HiveJdbcConfig.class);

    @Resource
    private Environment env;

    @Bean(name = "hiveJdbcDataSource")
    @Qualifier("hiveJdbcDataSource")
    public DataSource dataSource() {
        DataSource dataSource = new DataSource();
        dataSource.setUrl(env.getProperty("hadoop.url"));
        dataSource.setDriverClassName(env.getProperty("hadoop.driver-class-name"));
        dataSource.setUsername(env.getProperty("hadoop.user"));
        dataSource.setPassword(env.getProperty("hadoop.password"));
        logger.debug("Hive DataSource Inject Successfully...");
        return dataSource;
    }

    @Bean(name = "hiveJdbcTemplate")
    public JdbcTemplate hiveJdbcTemplate(@Qualifier("hiveJdbcDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
